
    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FKA8B62CB27ED2C937]') AND parent_object_id = OBJECT_ID('ACTION'))
alter table ACTION  drop constraint FKA8B62CB27ED2C937


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FK72DE035E2E2FE37C]') AND parent_object_id = OBJECT_ID('ACTION_RESPONSE'))
alter table ACTION_RESPONSE  drop constraint FK72DE035E2E2FE37C


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FKA06893E65550F0E2]') AND parent_object_id = OBJECT_ID('CHAT_ITEM'))
alter table CHAT_ITEM  drop constraint FKA06893E65550F0E2


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FK47894435EDB609A5]') AND parent_object_id = OBJECT_ID('EMERGENCY_FEEDBACK'))
alter table EMERGENCY_FEEDBACK  drop constraint FK47894435EDB609A5


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FK478944359FDBFC63]') AND parent_object_id = OBJECT_ID('EMERGENCY_FEEDBACK'))
alter table EMERGENCY_FEEDBACK  drop constraint FK478944359FDBFC63


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FK47894435950EDEFC]') AND parent_object_id = OBJECT_ID('EMERGENCY_FEEDBACK'))
alter table EMERGENCY_FEEDBACK  drop constraint FK47894435950EDEFC


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FK478944355550F0E2]') AND parent_object_id = OBJECT_ID('EMERGENCY_FEEDBACK'))
alter table EMERGENCY_FEEDBACK  drop constraint FK478944355550F0E2


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FKB402A7CFFD371FE4]') AND parent_object_id = OBJECT_ID('EMERGENCY_INCIDENT'))
alter table EMERGENCY_INCIDENT  drop constraint FKB402A7CFFD371FE4


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FK5ADB7A49FFE751FF]') AND parent_object_id = OBJECT_ID('ENTITY_TAG'))
alter table ENTITY_TAG  drop constraint FK5ADB7A49FFE751FF


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FK476008C92E2FE37C]') AND parent_object_id = OBJECT_ID('FILE_ATTACHMENT'))
alter table FILE_ATTACHMENT  drop constraint FK476008C92E2FE37C


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FK476008C910A453BC]') AND parent_object_id = OBJECT_ID('FILE_ATTACHMENT'))
alter table FILE_ATTACHMENT  drop constraint FK476008C910A453BC


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FK476008C95550F0E2]') AND parent_object_id = OBJECT_ID('FILE_ATTACHMENT'))
alter table FILE_ATTACHMENT  drop constraint FK476008C95550F0E2


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FK476008C96E797C67]') AND parent_object_id = OBJECT_ID('FILE_ATTACHMENT'))
alter table FILE_ATTACHMENT  drop constraint FK476008C96E797C67


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FK476008C9FD371FE4]') AND parent_object_id = OBJECT_ID('FILE_ATTACHMENT'))
alter table FILE_ATTACHMENT  drop constraint FK476008C9FD371FE4


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FK476008C9B24C1433]') AND parent_object_id = OBJECT_ID('FILE_ATTACHMENT'))
alter table FILE_ATTACHMENT  drop constraint FK476008C9B24C1433


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FK476008C9C529C8B9]') AND parent_object_id = OBJECT_ID('FILE_ATTACHMENT'))
alter table FILE_ATTACHMENT  drop constraint FK476008C9C529C8B9


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FK288ED046469CCB8E]') AND parent_object_id = OBJECT_ID('JOB'))
alter table JOB  drop constraint FK288ED046469CCB8E


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FKE5ECF8866E797C67]') AND parent_object_id = OBJECT_ID('Measurements'))
alter table Measurements  drop constraint FKE5ECF8866E797C67


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FKFB2A60DF6E797C67]') AND parent_object_id = OBJECT_ID('JOB_CHANGE_REQUEST'))
alter table JOB_CHANGE_REQUEST  drop constraint FKFB2A60DF6E797C67


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FKA12D91416E797C67]') AND parent_object_id = OBJECT_ID('JOB_HISTORY'))
alter table JOB_HISTORY  drop constraint FKA12D91416E797C67


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FKCA7D4EA42D4CA2BD]') AND parent_object_id = OBJECT_ID('MACHINE'))
alter table MACHINE  drop constraint FKCA7D4EA42D4CA2BD


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FKD2FDBBF15B2FD61F]') AND parent_object_id = OBJECT_ID('MACHINE_SYNONYM'))
alter table MACHINE_SYNONYM  drop constraint FKD2FDBBF15B2FD61F


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FKA3A71FB9C529C8B9]') AND parent_object_id = OBJECT_ID('MEASUREMENT_DATA'))
alter table MEASUREMENT_DATA  drop constraint FKA3A71FB9C529C8B9


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FKDE8275CFB801C927]') AND parent_object_id = OBJECT_ID('RolesToPrivileges'))
alter table RolesToPrivileges  drop constraint FKDE8275CFB801C927


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FKDE8275CF5A3F698F]') AND parent_object_id = OBJECT_ID('RolesToPrivileges'))
alter table RolesToPrivileges  drop constraint FKDE8275CF5A3F698F


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FK637044D15550F0E2]') AND parent_object_id = OBJECT_ID('SCRIBE'))
alter table SCRIBE  drop constraint FK637044D15550F0E2


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FKA24496D4C553E6F7]') AND parent_object_id = OBJECT_ID('STATUS_BOARD_ENTRY'))
alter table STATUS_BOARD_ENTRY  drop constraint FKA24496D4C553E6F7


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FKA24496D45550F0E2]') AND parent_object_id = OBJECT_ID('STATUS_BOARD_ENTRY'))
alter table STATUS_BOARD_ENTRY  drop constraint FKA24496D45550F0E2


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FKE4671E28DBBCC58A]') AND parent_object_id = OBJECT_ID('SYSTEM_CODE_DATA'))
alter table SYSTEM_CODE_DATA  drop constraint FKE4671E28DBBCC58A


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FKD0008D073406048E]') AND parent_object_id = OBJECT_ID('DepartmentToSystemModule'))
alter table DepartmentToSystemModule  drop constraint FKD0008D073406048E


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FKD0008D0713F3C274]') AND parent_object_id = OBJECT_ID('DepartmentToSystemModule'))
alter table DepartmentToSystemModule  drop constraint FKD0008D0713F3C274


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FK1E019CAF7D60858F]') AND parent_object_id = OBJECT_ID('SYSTEM_MODULE_PRIVILEGE'))
alter table SYSTEM_MODULE_PRIVILEGE  drop constraint FK1E019CAF7D60858F


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FK1E019CAF13F3C274]') AND parent_object_id = OBJECT_ID('SYSTEM_MODULE_PRIVILEGE'))
alter table SYSTEM_MODULE_PRIVILEGE  drop constraint FK1E019CAF13F3C274


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FKFA6E2927F9961078]') AND parent_object_id = OBJECT_ID('SYSTEM_RESOURCE_MAP'))
alter table SYSTEM_RESOURCE_MAP  drop constraint FKFA6E2927F9961078


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FKFA6E2927FD371FE4]') AND parent_object_id = OBJECT_ID('SYSTEM_RESOURCE_MAP'))
alter table SYSTEM_RESOURCE_MAP  drop constraint FKFA6E2927FD371FE4


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FKFA6E29275A3F698F]') AND parent_object_id = OBJECT_ID('SYSTEM_RESOURCE_MAP'))
alter table SYSTEM_RESOURCE_MAP  drop constraint FKFA6E29275A3F698F


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FKFA6E29273406048E]') AND parent_object_id = OBJECT_ID('SYSTEM_RESOURCE_MAP'))
alter table SYSTEM_RESOURCE_MAP  drop constraint FKFA6E29273406048E


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FKFA6E2927361E1705]') AND parent_object_id = OBJECT_ID('SYSTEM_RESOURCE_MAP'))
alter table SYSTEM_RESOURCE_MAP  drop constraint FKFA6E2927361E1705


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FK8374D44BCD787822]') AND parent_object_id = OBJECT_ID('TEMPLATE_MACHINERY'))
alter table TEMPLATE_MACHINERY  drop constraint FK8374D44BCD787822


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FK8374D44BF759A823]') AND parent_object_id = OBJECT_ID('TEMPLATE_MACHINERY'))
alter table TEMPLATE_MACHINERY  drop constraint FK8374D44BF759A823


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FK7E68F3AAF7CE787]') AND parent_object_id = OBJECT_ID('USER_MASTER'))
alter table USER_MASTER  drop constraint FK7E68F3AAF7CE787


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FK7E68F3A2E2FE37C]') AND parent_object_id = OBJECT_ID('USER_MASTER'))
alter table USER_MASTER  drop constraint FK7E68F3A2E2FE37C


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FK7E68F3A5A3F698F]') AND parent_object_id = OBJECT_ID('USER_MASTER'))
alter table USER_MASTER  drop constraint FK7E68F3A5A3F698F


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FK7E68F3AFD371FE4]') AND parent_object_id = OBJECT_ID('USER_MASTER'))
alter table USER_MASTER  drop constraint FK7E68F3AFD371FE4


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FK4AACB986FA78E1C1]') AND parent_object_id = OBJECT_ID('VESSEL'))
alter table VESSEL  drop constraint FK4AACB986FA78E1C1


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FK373C551EB24C1433]') AND parent_object_id = OBJECT_ID('VESSEL_MACHINE'))
alter table VESSEL_MACHINE  drop constraint FK373C551EB24C1433


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FK373C551EFD371FE4]') AND parent_object_id = OBJECT_ID('VESSEL_MACHINE'))
alter table VESSEL_MACHINE  drop constraint FK373C551EFD371FE4


    if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FKC2A7D73F6E797C67]') AND parent_object_id = OBJECT_ID('WORK_ORDER'))
alter table WORK_ORDER  drop constraint FKC2A7D73F6E797C67


    if exists (select * from dbo.sysobjects where id = object_id(N'ACTION') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table ACTION

    if exists (select * from dbo.sysobjects where id = object_id(N'ACTION_RESPONSE') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table ACTION_RESPONSE

    if exists (select * from dbo.sysobjects where id = object_id(N'CHAT_ITEM') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table CHAT_ITEM

    if exists (select * from dbo.sysobjects where id = object_id(N'DEPARTMENT') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table DEPARTMENT

    if exists (select * from dbo.sysobjects where id = object_id(N'EMERGENCY_FEEDBACK') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table EMERGENCY_FEEDBACK

    if exists (select * from dbo.sysobjects where id = object_id(N'EMERGENCY_INCIDENT') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table EMERGENCY_INCIDENT

    if exists (select * from dbo.sysobjects where id = object_id(N'ENTITY_TAG') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table ENTITY_TAG

    if exists (select * from dbo.sysobjects where id = object_id(N'FILE_ATTACHMENT') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table FILE_ATTACHMENT

    if exists (select * from dbo.sysobjects where id = object_id(N'JOB') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table JOB

    if exists (select * from dbo.sysobjects where id = object_id(N'Measurements') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table Measurements

    if exists (select * from dbo.sysobjects where id = object_id(N'JOB_CHANGE_REQUEST') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table JOB_CHANGE_REQUEST

    if exists (select * from dbo.sysobjects where id = object_id(N'JOB_HISTORY') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table JOB_HISTORY

    if exists (select * from dbo.sysobjects where id = object_id(N'MACHINE') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table MACHINE

    if exists (select * from dbo.sysobjects where id = object_id(N'MACHINE_SYNONYM') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table MACHINE_SYNONYM

    if exists (select * from dbo.sysobjects where id = object_id(N'MEASUREMENT_DATA') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table MEASUREMENT_DATA

    if exists (select * from dbo.sysobjects where id = object_id(N'ROLE') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table ROLE

    if exists (select * from dbo.sysobjects where id = object_id(N'RolesToPrivileges') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table RolesToPrivileges

    if exists (select * from dbo.sysobjects where id = object_id(N'SCRIBE') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table SCRIBE

    if exists (select * from dbo.sysobjects where id = object_id(N'STATUS_BOARD_ENTRY') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table STATUS_BOARD_ENTRY

    if exists (select * from dbo.sysobjects where id = object_id(N'STATUS_BOARD_ITEM') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table STATUS_BOARD_ITEM

    if exists (select * from dbo.sysobjects where id = object_id(N'SYSTEM_CODE') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table SYSTEM_CODE

    if exists (select * from dbo.sysobjects where id = object_id(N'SYSTEM_CODE_DATA') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table SYSTEM_CODE_DATA

    if exists (select * from dbo.sysobjects where id = object_id(N'SYSTEM_MODULE') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table SYSTEM_MODULE

    if exists (select * from dbo.sysobjects where id = object_id(N'DepartmentToSystemModule') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table DepartmentToSystemModule

    if exists (select * from dbo.sysobjects where id = object_id(N'SYSTEM_MODULE_PRIVILEGE') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table SYSTEM_MODULE_PRIVILEGE

    if exists (select * from dbo.sysobjects where id = object_id(N'SYSTEM_RESOURCE_MAP') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table SYSTEM_RESOURCE_MAP

    if exists (select * from dbo.sysobjects where id = object_id(N'TAG') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table TAG

    if exists (select * from dbo.sysobjects where id = object_id(N'TEMPLATE') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table TEMPLATE

    if exists (select * from dbo.sysobjects where id = object_id(N'TEMPLATE_MACHINERY') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table TEMPLATE_MACHINERY

    if exists (select * from dbo.sysobjects where id = object_id(N'USER_IDENTITY') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table USER_IDENTITY

    if exists (select * from dbo.sysobjects where id = object_id(N'USER_MASTER') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table USER_MASTER

    if exists (select * from dbo.sysobjects where id = object_id(N'VESSEL') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table VESSEL

    if exists (select * from dbo.sysobjects where id = object_id(N'VESSEL_MACHINE') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table VESSEL_MACHINE

    if exists (select * from dbo.sysobjects where id = object_id(N'WEB_PAGE') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table WEB_PAGE

    if exists (select * from dbo.sysobjects where id = object_id(N'WORK_ORDER') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table WORK_ORDER

    create table ACTION (
        ID UNIQUEIDENTIFIER not null,
       TITLE NVARCHAR(255) null,
       DESCRIPTION NVARCHAR(255) null,
       NON_CONFOR_DESCRIPTION NVARCHAR(255) null,
       RESPONSE_DUE_DATE DATETIME null,
       PRIORITY NVARCHAR(255) null,
       ACTION_TYPE NVARCHAR(255) null,
       SOURCE NVARCHAR(255) null,
       STATUS NVARCHAR(255) null,
       IS_RELEASED BIT null,
       RELEASED_DATE DATETIME null,
       RELEASED_BY UNIQUEIDENTIFIER null,
       IS_DELETED BIT null,
       CREATED_BY UNIQUEIDENTIFIER null,
       CREATED_DATE DATETIME null,
       UPDATED_BY UNIQUEIDENTIFIER null,
       UPDATED_DATE DATETIME null,
       WF_CODE NVARCHAR(255) null,
       Responder_id UNIQUEIDENTIFIER null,
       primary key (ID)
    )

    create table ACTION_RESPONSE (
        ID UNIQUEIDENTIFIER not null,
       RESPONSE NVARCHAR(255) null,
       REVIEWER_COMMENTS NVARCHAR(255) null,
       STATUS NVARCHAR(255) null,
       IS_DELETED BIT null,
       CREATED_BY UNIQUEIDENTIFIER null,
       CREATED_DATE DATETIME null,
       UPDATED_BY UNIQUEIDENTIFIER null,
       UPDATED_DATE DATETIME null,
       Action_id UNIQUEIDENTIFIER null,
       primary key (ID)
    )

    create table CHAT_ITEM (
        ID UNIQUEIDENTIFIER not null,
       MESSAGE_INDEX INT null,
       MESSAGE NVARCHAR(255) null,
       CONVERSATION_ID UNIQUEIDENTIFIER null,
       PARENT_ID UNIQUEIDENTIFIER null,
       CREATED_BY UNIQUEIDENTIFIER null,
       CREATED_DATE DATETIME null,
       EmergencyIncident_id UNIQUEIDENTIFIER null,
       primary key (ID)
    )

    create table DEPARTMENT (
        ID UNIQUEIDENTIFIER not null,
       NAME NVARCHAR(255) null,
       LOCATION NVARCHAR(255) null,
       IS_DELETED BIT null,
       primary key (ID)
    )

    create table EMERGENCY_FEEDBACK (
        ID UNIQUEIDENTIFIER not null,
       TYPE NVARCHAR(255) null,
       COMMENTS NVARCHAR(255) null,
       CORRECTIVE_ACTION NVARCHAR(255) null,
       RESPONSE_DUE_DATE DATETIME null,
       STATUS NVARCHAR(255) null,
       IS_DELETED BIT null,
       CREATED_BY UNIQUEIDENTIFIER null,
       CREATED_DATE DATETIME null,
       UPDATED_BY UNIQUEIDENTIFIER null,
       UPDATED_DATE DATETIME null,
       AssignedTo_id UNIQUEIDENTIFIER null,
       ReviewTo_id UNIQUEIDENTIFIER null,
       CorrectiveActionInstance_id UNIQUEIDENTIFIER null,
       EmergencyIncident_id UNIQUEIDENTIFIER null,
       primary key (ID)
    )

    create table EMERGENCY_INCIDENT (
        ID UNIQUEIDENTIFIER not null,
       TITLE NVARCHAR(255) null,
       FIRST_INCIDENT_REPORT_TIME DATETIME null,
       IS_INCIDENT BIT null,
       IS_CLOSED BIT null,
       CLOSED_DATE DATETIME null,
       CLOSED_BY UNIQUEIDENTIFIER null,
       CLOSE_COMMENT NVARCHAR(255) null,
       IS_DELETED BIT null,
       DCTM_FOLDER_CODE NVARCHAR(255) null,
       CREATED_BY UNIQUEIDENTIFIER null,
       CREATED_DATE DATETIME null,
       UPDATED_BY UNIQUEIDENTIFIER null,
       UPDATED_DATE DATETIME null,
       Vessel_id UNIQUEIDENTIFIER null,
       primary key (ID)
    )

    create table ENTITY_TAG (
        ID UNIQUEIDENTIFIER not null,
       ENTITY_ID UNIQUEIDENTIFIER null,
       ENTITY_TABLE NVARCHAR(255) null,
       URL NVARCHAR(255) null,
       TagAttached_id UNIQUEIDENTIFIER null,
       primary key (ID)
    )

    create table FILE_ATTACHMENT (
        ID UNIQUEIDENTIFIER not null,
       TITLE NVARCHAR(255) null,
       DESCRIPTION NVARCHAR(255) null,
       FILE_NAME NVARCHAR(255) null,
       FILE_SIZE BIGINT null,
       REPOSITORY_CODE NVARCHAR(255) null,
       LOCATION NVARCHAR(255) null,
       UPLOAD_DATE DATETIME null,
       UPLOAD_BY UNIQUEIDENTIFIER null,
       Action_id UNIQUEIDENTIFIER null,
       ActionResponse_id UNIQUEIDENTIFIER null,
       EmergencyIncident_id UNIQUEIDENTIFIER null,
       Job_id UNIQUEIDENTIFIER null,
       Vessel_id UNIQUEIDENTIFIER null,
       Parent_id UNIQUEIDENTIFIER null,
       WorkOrder_id UNIQUEIDENTIFIER null,
       primary key (ID)
    )

    create table JOB (
        ID UNIQUEIDENTIFIER not null,
       CODE NVARCHAR(255) null,
       TITLE NVARCHAR(255) null,
       DESCRIPTION NVARCHAR(255) null,
       PERIODICITY INT null,
       PERIODICITY_UNIT NVARCHAR(255) null,
       PRIORITY NVARCHAR(255) null,
       TYPE NVARCHAR(255) null,
       JOB_VERSION INT null,
       IS_DELETED BIT null,
       IS_RELEASED BIT null,
       RELEASED_DATE DATETIME null,
       RELEASED_BY UNIQUEIDENTIFIER null,
       CREATED_BY UNIQUEIDENTIFIER null,
       CREATED_DATE DATETIME null,
       UPDATED_BY UNIQUEIDENTIFIER null,
       UPDATED_DATE DATETIME null,
       VesselMachine_id UNIQUEIDENTIFIER null,
       primary key (ID)
    )

    create table Measurements (
        Job_id UNIQUEIDENTIFIER not null,
       Value NVARCHAR(255) null
    )

    create table JOB_CHANGE_REQUEST (
        ID UNIQUEIDENTIFIER not null,
       CODE NVARCHAR(255) null,
       TITLE NVARCHAR(255) null,
       DESCRIPTION NVARCHAR(255) null,
       PERIODICITY INT null,
       PERIODICITY_UNIT NVARCHAR(255) null,
       PRIORITY NVARCHAR(255) null,
       MEASUREMENTS NVARCHAR(255) null,
       IS_RELEASED BIT null,
       RELEASED_DATE DATETIME null,
       IS_DELETED BIT null,
       RELEASED_BY UNIQUEIDENTIFIER null,
       IS_APPROVED BIT null,
       ACTION_DATE DATETIME null,
       ACTION_BY UNIQUEIDENTIFIER null,
       CREATED_BY UNIQUEIDENTIFIER null,
       CREATED_DATE DATETIME null,
       UPDATED_BY UNIQUEIDENTIFIER null,
       UPDATED_DATE DATETIME null,
       Job_id UNIQUEIDENTIFIER null,
       primary key (ID)
    )

    create table JOB_HISTORY (
        ID UNIQUEIDENTIFIER not null,
       CODE NVARCHAR(255) null,
       TITLE NVARCHAR(255) null,
       DESCRIPTION NVARCHAR(255) null,
       PERIODICITY INT null,
       PERIODICITY_UNIT NVARCHAR(255) null,
       PRIORITY NVARCHAR(255) null,
       TYPE NVARCHAR(255) null,
       JOB_VERSION INT null,
       MEASUREMENTS NVARCHAR(255) null,
       UPDATED_BY UNIQUEIDENTIFIER null,
       UPDATED_DATE DATETIME null,
       Job_id UNIQUEIDENTIFIER null,
       primary key (ID)
    )

    create table MACHINE (
        ID UNIQUEIDENTIFIER not null,
       NAME NVARCHAR(255) null,
       DESCRIPTION NVARCHAR(255) null,
       SPECIFICATIONS NVARCHAR(255) null,
       TYPE NVARCHAR(255) null,
       RUNNING_HOURS_REQURED BIT null,
       IS_ROTATING_EQUIPMENT BIT null,
       IS_STORE_REQUIRED BIT null,
       IS_BUSINESS_CRITICAL BIT null,
       IS_SAFETY_CRITICAL BIT null,
       IS_ENVIRONMENT_CRITICAL BIT null,
       IS_MANDATORY BIT null,
       IS_DISABLED BIT null,
       IS_DELETED BIT null,
       CREATED_BY UNIQUEIDENTIFIER null,
       CREATED_DATE DATETIME null,
       UPDATED_BY UNIQUEIDENTIFIER null,
       UPDATED_DATE DATETIME null,
       Parent_id UNIQUEIDENTIFIER null,
       primary key (ID)
    )

    create table MACHINE_SYNONYM (
        ID UNIQUEIDENTIFIER not null,
       NAME NVARCHAR(255) null,
       Machine_id UNIQUEIDENTIFIER null,
       primary key (ID)
    )

    create table MEASUREMENT_DATA (
        ID UNIQUEIDENTIFIER not null,
       TITLE NVARCHAR(255) null,
       VALUE NVARCHAR(255) null,
       TAKEN_BY UNIQUEIDENTIFIER null,
       TAKEN_ON DATETIME null,
       IS_DELETED BIT null,
       WorkOrder_id UNIQUEIDENTIFIER null,
       primary key (ID)
    )

    create table ROLE (
        ID UNIQUEIDENTIFIER not null,
       NAME NVARCHAR(255) null unique,
       DESCRIPTION NVARCHAR(255) null,
       CAN_MODIFY BIT null,
       IS_DISABLED BIT null,
       IS_DELETED BIT null,
       CREATED_BY UNIQUEIDENTIFIER null,
       CREATED_DATE DATETIME null,
       UPDATED_BY UNIQUEIDENTIFIER null,
       UPDATED_DATE DATETIME null,
       primary key (ID)
    )

    create table RolesToPrivileges (
        Role_id UNIQUEIDENTIFIER not null,
       SystemModulePrivilege_id UNIQUEIDENTIFIER not null
    )

    create table SCRIBE (
        ID UNIQUEIDENTIFIER not null,
       SCRIBE_INDEX INT null,
       MESSAGE NVARCHAR(255) null,
       SHORT_ITEM_NAME NVARCHAR(255) null,
       MESSAGE_TYPE NVARCHAR(255) null,
       CREATED_BY UNIQUEIDENTIFIER null,
       CREATED_DATE DATETIME null,
       UPDATED_BY UNIQUEIDENTIFIER null,
       UPDATED_DATE DATETIME null,
       EmergencyIncident_id UNIQUEIDENTIFIER null,
       primary key (ID)
    )

    create table STATUS_BOARD_ENTRY (
        ID UNIQUEIDENTIFIER not null,
       STATUS_ENTRY NVARCHAR(255) null,
       CREATED_DATE DATETIME null,
       CREATED_BY UNIQUEIDENTIFIER null,
       StatusItem_id UNIQUEIDENTIFIER null,
       EmergencyIncident_id UNIQUEIDENTIFIER null,
       primary key (ID)
    )

    create table STATUS_BOARD_ITEM (
        ID UNIQUEIDENTIFIER not null,
       TITLE NVARCHAR(255) null,
       SHORT_NAME NVARCHAR(255) null,
       SEQUENCE INT null,
       IS_DELETED BIT null,
       primary key (ID)
    )

    create table SYSTEM_CODE (
        ID UNIQUEIDENTIFIER not null,
       NAME NVARCHAR(255) null,
       IS_DELETED BIT null,
       primary key (ID)
    )

    create table SYSTEM_CODE_DATA (
        ID UNIQUEIDENTIFIER not null,
       NAME NVARCHAR(255) null,
       VALUE NVARCHAR(255) null,
       PARENT_I_D UNIQUEIDENTIFIER null,
       IS_DELETED BIT null,
       SystemCode_id UNIQUEIDENTIFIER null,
       primary key (ID)
    )

    create table SYSTEM_MODULE (
        ID UNIQUEIDENTIFIER not null,
       NAME NVARCHAR(255) null,
       DESCRIPTION NVARCHAR(255) null,
       URL NVARCHAR(255) null,
       INDEX_NUMBER INT null,
       PARENT_MODULE UNIQUEIDENTIFIER null,
       IS_LEAF BIT null,
       IS_DISABLED BIT null,
       IS_DELETED BIT null,
       LOCATION NVARCHAR(255) null,
       primary key (ID)
    )

    create table DepartmentToSystemModule (
        SystemModule_id UNIQUEIDENTIFIER not null,
       Department_id UNIQUEIDENTIFIER not null
    )

    create table SYSTEM_MODULE_PRIVILEGE (
        ID UNIQUEIDENTIFIER not null,
       NAME NVARCHAR(255) null,
       DESCRIPTION NVARCHAR(255) null,
       INDEX_NUMBER INT null,
       PRIVILEGE_CODE NVARCHAR(255) null,
       IS_DISABLED BIT null,
       IS_DELETED BIT null,
       Module_id UNIQUEIDENTIFIER null,
       SystemModule_id UNIQUEIDENTIFIER null,
       primary key (ID)
    )

    create table SYSTEM_RESOURCE_MAP (
        ID UNIQUEIDENTIFIER not null,
       GROUP_ID NVARCHAR(255) null,
       User_id UNIQUEIDENTIFIER null,
       Vessel_id UNIQUEIDENTIFIER null,
       Role_id UNIQUEIDENTIFIER null,
       Department_id UNIQUEIDENTIFIER null,
       UserMaster_id UNIQUEIDENTIFIER null,
       primary key (ID)
    )

    create table TAG (
        ID UNIQUEIDENTIFIER not null,
       NAME NVARCHAR(255) null,
       IS_USER_DEFINED BIT null,
       CREATED_BY UNIQUEIDENTIFIER null,
       CREATED_DATE DATETIME null,
       UPDATED_BY UNIQUEIDENTIFIER null,
       UPDATED_DATE DATETIME null,
       primary key (ID)
    )

    create table TEMPLATE (
        ID UNIQUEIDENTIFIER not null,
       NAME NVARCHAR(255) null,
       DESCRIPTION NVARCHAR(255) null,
       IS_DISABLED BIT null,
       IS_DELETED BIT null,
       CREATED_BY UNIQUEIDENTIFIER null,
       CREATED_DATE DATETIME null,
       UPDATED_BY UNIQUEIDENTIFIER null,
       UPDATED_DATE DATETIME null,
       primary key (ID)
    )

    create table TEMPLATE_MACHINERY (
        ID UNIQUEIDENTIFIER not null,
       PARENT_ID UNIQUEIDENTIFIER null,
       MachineItem_id UNIQUEIDENTIFIER null,
       Template_id UNIQUEIDENTIFIER null,
       primary key (ID)
    )

    create table USER_IDENTITY (
        ID UNIQUEIDENTIFIER not null,
       LOGIN_NAME NVARCHAR(255) null,
       PASSWORD NVARCHAR(255) null,
       IS_AD_USER BIT null,
       LAST_LOGIN_TIME DATETIME null,
       IP_ADDRESS NVARCHAR(255) null,
       primary key (ID)
    )

    create table USER_MASTER (
        ID UNIQUEIDENTIFIER not null,
       STAFF_CODE INT null,
       LOCATION NVARCHAR(255) null,
       FIRST_NAME NVARCHAR(255) null,
       LAST_NAME NVARCHAR(255) null,
       SALUTATION NVARCHAR(255) null,
       E_MAIL NVARCHAR(255) null,
       PHONE_NUMBER NVARCHAR(255) null,
       IS_SYSTEM_ADMIN BIT null,
       IS_DISABLED BIT null,
       IS_DELETED BIT null,
       CREATED_BY UNIQUEIDENTIFIER null,
       CREATED_DATE DATETIME null,
       UPDATED_BY UNIQUEIDENTIFIER null,
       UPDATED_DATE DATETIME null,
       Identity_id UNIQUEIDENTIFIER null,
       Action_id UNIQUEIDENTIFIER null,
       Role_id UNIQUEIDENTIFIER null,
       Vessel_id UNIQUEIDENTIFIER null,
       primary key (ID)
    )

    create table VESSEL (
        ID UNIQUEIDENTIFIER not null,
       RECORD_NUM INT null,
       NAME NVARCHAR(255) null,
       SHORT_NAME NVARCHAR(255) null,
       IMO_NUMBER NVARCHAR(255) null,
       CALL_SIGN NVARCHAR(255) null,
       HULL_NO NVARCHAR(255) null,
       PORT_OF_REGISTRY NVARCHAR(255) null,
       FLAG NVARCHAR(255) null,
       INMARSAT_PHONE_NO NVARCHAR(255) null,
       FAX NVARCHAR(255) null,
       E_MAIL NVARCHAR(255) null,
       DB_SYNC_MAIL NVARCHAR(255) null,
       CLASSIFICATION_SOCIETY NVARCHAR(255) null,
       IS_DISABLED BIT null,
       IS_RELEASED BIT null,
       RELEASED_DATE DATETIME null,
       RELEASED_BY UNIQUEIDENTIFIER null,
       IS_DELETED BIT null,
       CREATED_BY UNIQUEIDENTIFIER null,
       CREATED_DATE DATETIME null,
       UPDATED_BY UNIQUEIDENTIFIER null,
       UPDATED_DATE DATETIME null,
       SystemsTemplate_id UNIQUEIDENTIFIER null,
       primary key (ID)
    )

    create table VESSEL_MACHINE (
        ID UNIQUEIDENTIFIER not null,
       ITEM_ID UNIQUEIDENTIFIER null,
       NAME NVARCHAR(255) null,
       DESCRIPTION NVARCHAR(255) null,
       SPECIFICATIONS NVARCHAR(255) null,
       VESSEL_ITEM_TYPE NVARCHAR(255) null,
       IS_BUSINESS_CRITICAL BIT null,
       IS_SAFETY_CRITICAL BIT null,
       IS_ENVIRONMENT_CRITICAL BIT null,
       IS_MANDATORY BIT null,
       IS_DISABLED BIT null,
       IS_DELETED BIT null,
       CREATED_BY UNIQUEIDENTIFIER null,
       CREATED_DATE DATETIME null,
       UPDATED_BY UNIQUEIDENTIFIER null,
       UPDATED_DATE DATETIME null,
       Parent_id UNIQUEIDENTIFIER null,
       Vessel_id UNIQUEIDENTIFIER null,
       primary key (ID)
    )

    create table WEB_PAGE (
        ID UNIQUEIDENTIFIER not null,
       TITLE NVARCHAR(255) null,
       DESCRIPTION NVARCHAR(255) null,
       RELATIVE_URL NVARCHAR(255) null,
       PERMISSION_SET NVARCHAR(255) null,
       TYPE NVARCHAR(255) null,
       SEQUNECE_NO INT null,
       PARENT_I_D UNIQUEIDENTIFIER null,
       ZONE NVARCHAR(255) null,
       PAGE_CODE NVARCHAR(255) null,
       IS_ENABLED BIT null,
       primary key (ID)
    )

    create table WORK_ORDER (
        ID UNIQUEIDENTIFIER not null,
       CODE NVARCHAR(255) null,
       TITLE NVARCHAR(255) null,
       DESCRIPTION NVARCHAR(255) null,
       PERIODICITY INT null,
       PERIODICITY_UNIT NVARCHAR(255) null,
       PRIORITY NVARCHAR(255) null,
       TYPE NVARCHAR(255) null,
       JOB_VERSION INT null,
       WORKDONE_REPORT NVARCHAR(255) null,
       IS_RELEASED BIT null,
       RELEASED_DATE DATETIME null,
       IS_DELETED BIT null,
       RELEASED_BY UNIQUEIDENTIFIER null,
       CREATED_BY UNIQUEIDENTIFIER null,
       CREATED_DATE DATETIME null,
       UPDATED_BY UNIQUEIDENTIFIER null,
       UPDATED_DATE DATETIME null,
       Job_id UNIQUEIDENTIFIER null,
       primary key (ID)
    )

    alter table ACTION 
        add constraint FKA8B62CB27ED2C937 
        foreign key (Responder_id) 
        references USER_MASTER

    alter table ACTION_RESPONSE 
        add constraint FK72DE035E2E2FE37C 
        foreign key (Action_id) 
        references ACTION

    alter table CHAT_ITEM 
        add constraint FKA06893E65550F0E2 
        foreign key (EmergencyIncident_id) 
        references EMERGENCY_INCIDENT

    alter table EMERGENCY_FEEDBACK 
        add constraint FK47894435EDB609A5 
        foreign key (AssignedTo_id) 
        references USER_MASTER

    alter table EMERGENCY_FEEDBACK 
        add constraint FK478944359FDBFC63 
        foreign key (ReviewTo_id) 
        references USER_MASTER

    alter table EMERGENCY_FEEDBACK 
        add constraint FK47894435950EDEFC 
        foreign key (CorrectiveActionInstance_id) 
        references ACTION

    alter table EMERGENCY_FEEDBACK 
        add constraint FK478944355550F0E2 
        foreign key (EmergencyIncident_id) 
        references EMERGENCY_INCIDENT

    alter table EMERGENCY_INCIDENT 
        add constraint FKB402A7CFFD371FE4 
        foreign key (Vessel_id) 
        references VESSEL

    alter table ENTITY_TAG 
        add constraint FK5ADB7A49FFE751FF 
        foreign key (TagAttached_id) 
        references TAG

    alter table FILE_ATTACHMENT 
        add constraint FK476008C92E2FE37C 
        foreign key (Action_id) 
        references ACTION

    alter table FILE_ATTACHMENT 
        add constraint FK476008C910A453BC 
        foreign key (ActionResponse_id) 
        references ACTION_RESPONSE

    alter table FILE_ATTACHMENT 
        add constraint FK476008C95550F0E2 
        foreign key (EmergencyIncident_id) 
        references EMERGENCY_INCIDENT

    alter table FILE_ATTACHMENT 
        add constraint FK476008C96E797C67 
        foreign key (Job_id) 
        references JOB

    alter table FILE_ATTACHMENT 
        add constraint FK476008C9FD371FE4 
        foreign key (Vessel_id) 
        references VESSEL

    alter table FILE_ATTACHMENT 
        add constraint FK476008C9B24C1433 
        foreign key (Parent_id) 
        references VESSEL_MACHINE

    alter table FILE_ATTACHMENT 
        add constraint FK476008C9C529C8B9 
        foreign key (WorkOrder_id) 
        references WORK_ORDER

    alter table JOB 
        add constraint FK288ED046469CCB8E 
        foreign key (VesselMachine_id) 
        references VESSEL_MACHINE

    alter table Measurements 
        add constraint FKE5ECF8866E797C67 
        foreign key (Job_id) 
        references JOB

    alter table JOB_CHANGE_REQUEST 
        add constraint FKFB2A60DF6E797C67 
        foreign key (Job_id) 
        references JOB

    alter table JOB_HISTORY 
        add constraint FKA12D91416E797C67 
        foreign key (Job_id) 
        references JOB

    alter table MACHINE 
        add constraint FKCA7D4EA42D4CA2BD 
        foreign key (Parent_id) 
        references MACHINE

    alter table MACHINE_SYNONYM 
        add constraint FKD2FDBBF15B2FD61F 
        foreign key (Machine_id) 
        references MACHINE

    alter table MEASUREMENT_DATA 
        add constraint FKA3A71FB9C529C8B9 
        foreign key (WorkOrder_id) 
        references WORK_ORDER

    alter table RolesToPrivileges 
        add constraint FKDE8275CFB801C927 
        foreign key (SystemModulePrivilege_id) 
        references SYSTEM_MODULE_PRIVILEGE

    alter table RolesToPrivileges 
        add constraint FKDE8275CF5A3F698F 
        foreign key (Role_id) 
        references ROLE

    alter table SCRIBE 
        add constraint FK637044D15550F0E2 
        foreign key (EmergencyIncident_id) 
        references EMERGENCY_INCIDENT

    alter table STATUS_BOARD_ENTRY 
        add constraint FKA24496D4C553E6F7 
        foreign key (StatusItem_id) 
        references STATUS_BOARD_ITEM

    alter table STATUS_BOARD_ENTRY 
        add constraint FKA24496D45550F0E2 
        foreign key (EmergencyIncident_id) 
        references EMERGENCY_INCIDENT

    alter table SYSTEM_CODE_DATA 
        add constraint FKE4671E28DBBCC58A 
        foreign key (SystemCode_id) 
        references SYSTEM_CODE

    alter table DepartmentToSystemModule 
        add constraint FKD0008D073406048E 
        foreign key (Department_id) 
        references DEPARTMENT

    alter table DepartmentToSystemModule 
        add constraint FKD0008D0713F3C274 
        foreign key (SystemModule_id) 
        references SYSTEM_MODULE

    alter table SYSTEM_MODULE_PRIVILEGE 
        add constraint FK1E019CAF7D60858F 
        foreign key (Module_id) 
        references SYSTEM_MODULE

    alter table SYSTEM_MODULE_PRIVILEGE 
        add constraint FK1E019CAF13F3C274 
        foreign key (SystemModule_id) 
        references SYSTEM_MODULE

    alter table SYSTEM_RESOURCE_MAP 
        add constraint FKFA6E2927F9961078 
        foreign key (User_id) 
        references USER_MASTER

    alter table SYSTEM_RESOURCE_MAP 
        add constraint FKFA6E2927FD371FE4 
        foreign key (Vessel_id) 
        references VESSEL

    alter table SYSTEM_RESOURCE_MAP 
        add constraint FKFA6E29275A3F698F 
        foreign key (Role_id) 
        references ROLE

    alter table SYSTEM_RESOURCE_MAP 
        add constraint FKFA6E29273406048E 
        foreign key (Department_id) 
        references DEPARTMENT

    alter table SYSTEM_RESOURCE_MAP 
        add constraint FKFA6E2927361E1705 
        foreign key (UserMaster_id) 
        references USER_MASTER

    alter table TEMPLATE_MACHINERY 
        add constraint FK8374D44BCD787822 
        foreign key (MachineItem_id) 
        references MACHINE

    alter table TEMPLATE_MACHINERY 
        add constraint FK8374D44BF759A823 
        foreign key (Template_id) 
        references TEMPLATE

    alter table USER_MASTER 
        add constraint FK7E68F3AAF7CE787 
        foreign key (Identity_id) 
        references USER_IDENTITY

    alter table USER_MASTER 
        add constraint FK7E68F3A2E2FE37C 
        foreign key (Action_id) 
        references ACTION

    alter table USER_MASTER 
        add constraint FK7E68F3A5A3F698F 
        foreign key (Role_id) 
        references ROLE

    alter table USER_MASTER 
        add constraint FK7E68F3AFD371FE4 
        foreign key (Vessel_id) 
        references VESSEL

    alter table VESSEL 
        add constraint FK4AACB986FA78E1C1 
        foreign key (SystemsTemplate_id) 
        references TEMPLATE

    alter table VESSEL_MACHINE 
        add constraint FK373C551EB24C1433 
        foreign key (Parent_id) 
        references VESSEL_MACHINE

    alter table VESSEL_MACHINE 
        add constraint FK373C551EFD371FE4 
        foreign key (Vessel_id) 
        references VESSEL

    alter table WORK_ORDER 
        add constraint FKC2A7D73F6E797C67 
        foreign key (Job_id) 
        references JOB
